<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/template.xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core">
    
    <ui:define name="title"></ui:define>
    <ui:define name="content">
        
       <!-- <c:if test="#{userBean.currentUser.role == 'ADMIN'}">-->
        
        <div id="adminmenu">
            <ui:include src="./admin/menu.xhtml"></ui:include> 
        </div>
       <br/><h2>Список заказов</h2>
        <h:form id="orders">
            <p:dataTable var="order" value="#{orderBean.allOrders}" id="orders" paginator="true" rows="6"   
        paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"  
        rowsPerPageTemplate="5,10,15">
                <p:column headerText="Имя заказчика" filterBy="#{order.idUser.surname}" >
                  <b><h:outputText value="#{order.idUser.surname} #{order.idUser.name}"/></b>  
                </p:column>
                <p:column headerText="Дата заказа">
                    <h:outputText value="#{order.dateOrder.toGMTString()}"/>  
                </p:column>
                <p:column headerText="Стоимость заказа">
                    <h:outputText value="#{order.totalCost}"/>
                </p:column> 
                <p:column headerText="Предоплата">
                    <h:outputText value="#{order.prepay}" />
                </p:column>
                <p:column headerText="Оплачен ли" filterBy="#{order.isPaid}">
                    <h:outputText value="#{order.isPaid}" />
                </p:column>
                <p:column>
                    <p:commandButton style="height: 25px; width: 25px;" icon="ui-icon-search" update=":orders:orderDetail1,:orders:tabFullOrder" oncomplete="orderDialog.show()" title="Просмотр заказа" >
                    <f:setPropertyActionListener value="#{order}" target="#{orderBean.selectedOrders}" />
                </p:commandButton>
                </p:column>
                
            </p:dataTable>
            <p:dialog modal="true" showEffect="fade" width="800" header="Подробная информация о заказе" widgetVar="orderDialog">
                <p:outputPanel layout="block" id="orderDetail1">
                    <p:panelGrid columns="4">
                        <h:outputText value="Имя клиента:"/>
                        <h:outputText value="#{orderBean.selectedOrders.idUser.surname}" />
                        <h:outputText value="#{orderBean.selectedOrders.idUser.name}" />
                        <h:outputText value="#{orderBean.selectedOrders.idUser.patronymic}" />
                        <h:outputText value="Дата заказа:"/>
                        <h:outputText value="#{orderBean.selectedOrders.dateOrder}" />
                        <h:outputText value="Стоимость:"/>
                        <h:outputText value="#{orderBean.selectedOrders.totalCost}" />
                        <h:outputText value="Предоплата:"/>
                        <h:outputText value="#{orderBean.selectedOrders.prepay}"/>
                        <h:outputText value="Остаток:"/>
                        <h:outputText value="#{orderBean.selectedOrders.totalCost-orderBean.selectedOrders.prepay}"/>
                        <h:outputText value="#{orderBean.selectedOrders.isPaid}" id="isPaidOrder"/>
                        <p:commandButton id="paidBtn" style="padding: 2px;" actionListener="#{orderBean.orderPaid}" icon="ui-icon-cart" value="Оплатить" update="isPaidOrder,:orders:orders" />    
                        
                    </p:panelGrid>
                    <p:tabView id="tabFullOrder"  dynamic="true" cache="true">
                        <p:tab id="tabOrderRoom" title="Номера">
                             <p:dataTable value="#{orderBean.selectedOrders.orderRoomList}" var="oroom">
                                <p:column>
                                    <h:outputText value="#{oroom.idRoomNumber.numberRoom}"/>
                                </p:column>
                                <p:column>
                                    <h:outputText value="#{oroom.dateBegin}"/>
                                </p:column>
                                <p:column>
                                    <h:outputText value="#{oroom.dateEnd}"/>
                                </p:column>
                            </p:dataTable>
                        </p:tab>
                        <p:tab id="tabOrderHall" title="Залы"></p:tab>
                        <p:tab id="tabOrderR" title="Ресторан"></p:tab>
                    </p:tabView>
                    
                  
                </p:outputPanel>
                <p:commandButton value="Print" type="button" icon="ui-icon-print">  
                    <p:printer target="orderDetail1" />  
                </p:commandButton>  
                    
                
            </p:dialog>
        </h:form>
        <br/>
        
        
        <br/><h2>Бронирование номера</h2>
        <h:form id="orderRoom">
            <p:dataGrid var="room" value="#{hotelRoomBean.freeRoom}" columns="7" 
                        rows="7"  paginator="true" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                        {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"                     
                        rowsPerPageTemplate="7,14,21,28,35">
                <p:panel  header="#{room.numberRoom}">
                    <p:panelGrid columns="1">
                        <h:outputText value="#{room.category}"/>
                        <h:outputText value="#{room.price}"/>
                            <p:commandLink update=":orderRoom:orderRoomDetail" oncomplete="roomOrder.show()" title="Забронирвать номер">
                                <h:outputText value="Забронировать" styleClass="ui-icon  ui-icon-plus"/>
                                <f:setPropertyActionListener value="#{room}" target="#{orderBean.hotelRoomOrder}"/>
                            </p:commandLink>    
                    </p:panelGrid>
                </p:panel>
                
            </p:dataGrid>
            <p:dialog width="800" widgetVar="roomOrder" id="orderRoomDg" header="Забронировать номер" modal="false"> 
                <p:outputPanel id="orderRoomDetail" layout="block">
                   
                    <p:schedule  value="#{orderBean.ordersRoomDate}" widgetVar="OrderHotelRoom" >
                        <p:ajax event="dateSelect"   oncomplete="eventDialog.show()" />
                           
                        <p:ajax event="eventSelect" update="dateSelectShedule" listener="#{orderBean.onEventSelect}" oncomplete="aq.show()"/>
                    </p:schedule>
                    <p:dialog header="aaa" widgetVar="aq">
                        <p:panelGrid columns="3" id="dateSelectShedule">
                            #{orderBean.event.startDate}</p:panelGrid> 
                    </p:dialog>
                    
                    <p:dialog widgetVar="eventDialog" id="aaa" draggable="false" width="900"  modal="false"  header="Забронировать номер">  
                      
                       <p:growl id="growlOrderRoom" sticky="true" showDetail="true"/>       
                       <p:wizard widgetVar="wiz" >
                           <p:tab id="userTab" title="Пользователь">
                               <p:panelGrid columns="2">
                                   <h:outputText value="Поиск по email"/>
                                   <p:inputText value="#{orderBean.userOrderEmail}">
                                       <p:ajax event="keyup" listener="#{orderBean.findUserByEmail}" update="newUserInfo"/> 
                                   </p:inputText>   
                               </p:panelGrid>
                               <p:panelGrid columns="4" id="newUserInfo">
                             <h:outputText value="Фамилия" />
                                    <p:inputText value="#{orderBean.userOrder.surname}"/> 
                                     
                                     <h:outputText value="Имя"/>
                                    <p:inputText value="#{orderBean.userOrder.name}" />
                                    <h:outputText value="Отчество:"/>
                     <p:inputText value="#{orderBean.userOrder.patronymic}" />
                     <h:outputText value="Email:"/>
                     <p:inputText value="#{orderBean.userOrder.email}" >    
                     </p:inputText>   
                     <h:outputText value="Телефон:"/>
                        <p:inputText value="#{orderBean.userOrder.phone}" />
                        <h:outputText value="Категория:"/>
                        <h:selectOneMenu value="#{orderBean.userOrder.category}">
                                       <f:selectItems value="#{userBean.category}"
                                                      var="categoryOrderUser"
                                                      itemLabel="#{categoryOrderUser}"
                                                      itemValue="#{categoryOrderUser}"
                                                      >
                                       </f:selectItems>
                                   </h:selectOneMenu>
                        <h:outputText  value="Инфомация о пользователе:"/>
                     <p:inputTextarea cols="30" value="#{orderBean.userOrder.info}" />
                     <h:outputText value="Статус:"/>
                     <p:inputText value="#{orderBean.userOrder.status}" />
                     <h:outputText value="Роль:"/>
                     <h:selectOneMenu value="#{orderBean.userOrder.role}">
                                    <f:selectItems value="#{userBean.role}"
                                                   var="roleOrderUser"
                                                   itemLabel="#{roleOrderUser}"
                                                   itemValue="#{roleOrderUser}"
                                                   >
                                    </f:selectItems>
                                </h:selectOneMenu>
                     <h:outputText value="Пароль:"/>
                     <p:inputText value="#{orderBean.userOrder.password}" />

                               </p:panelGrid>
                                  
                                
                           </p:tab>
                           <p:tab id="roomTab" title="Бронь номера">
                               <p:panelGrid columns="2" >
                                <h:outputText value="Дата заезда"/>
                                <p:calendar navigator="true" value="#{orderBean.orderRoom.dateBegin}"/>
                                <h:outputText value="Дата выезда"/>
                                <p:calendar navigator="true" value="#{orderBean.orderRoom.dateEnd}" />
                                <h:outputText value="Статус заказа"/>
                                <p:inputText value="#{orderBean.orderRoom.status}" />
                                <h:outputText value="Количество человек"/>
                                <p:inputText value="#{orderBean.orderRoom.countPeople}"/>
                               </p:panelGrid>
                           </p:tab>
                           <p:tab id="paidTab"  title="Стоимость">
                               <p:panelGrid  columns="2"> 
                                   <h:outputText value="К оплате:"/>
                                   <h:outputText value="#{orderBean.orderPaid}"/>
                                    <h:outputText value="Предоплата"/>
                                    <p:inputText value="#{orderBean.prepay}"/>
                                    
                                </p:panelGrid>
                           </p:tab>
                           <p:tab id="fullTab" title="Итог">
                               <p:panelGrid columns="2">
                                   <h:outputText value="Заселяющий:" />
                                   <h:outputText value="#{orderBean.userOrder.surname} #{orderBean.userOrder.name}  " />
                                   <h:outputText value="Номер:" />
                                   <h:outputText value="#{orderBean.hotelRoomOrder.numberRoom}   " />
                                   <h:outputText value="К оплате:" />
                                   <h:outputText value="#{orderBean.orderPaid}  " />
                                   <h:outputText value="предоплата:" />
                                   <h:outputText value="#{orderBean.prepay}" />
                                   <p:commandButton value="Заказать" update=":orders:orders,:orderRoom:orderRoomDetail" icon="ui-icon-cart" action="#{orderBean.saveOrder}" ></p:commandButton>
                               </p:panelGrid>
                               
                           </p:tab>
                       </p:wizard> 
                    </p:dialog>  
                     
                </p:outputPanel>
            </p:dialog>
        </h:form>
    
        
        <!--</c:if>-->
    </ui:define>
</ui:composition>
